'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const { departureStation, arrivalStation, type } = event
	let result = null
	try {
		const db = uniCloud.database()
		const Train = db.collection('train')
		if (type == "get") {
			result = await Train.where({
				departureStation: departureStation,
				arrivalStation: arrivalStation
			}).get()
			if (result.data.length) {
				return {
					code: 0,
					message: '查询成功',
					data: result
				}
			} else {
				return {
					code: -1,
					message: '暂无车次',
				}
			}

		}
	} catch (e) {
		//TODO handle the exception
		return {
			code: -1,
			message: '操作失败',
		}
	}
};
